package com.java.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.entity.RaceAccount;
import com.java.entity.RaceAdmin;
import com.java.service.AccountService;
import com.java.service.AdminService;
import com.java.util.MyCons;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;
import com.java.util.servlet.ServletUtil;

@RestController
@RequestMapping("/admin")
public class AdminController {

	@Autowired
	private AdminService adminService;
	@Autowired private AccountService accountService;

	@PostMapping("/info")
	public BaseRespone info() {
		RaceAdmin user = (RaceAdmin) ServletUtil.getSession().getAttribute(MyCons.ADMIN_ROLE);
		RaceAdmin admin = adminService.getAdmin(user.getAdminId());
		return BaseRespone.success(admin);
	}

	@PostMapping("/saveInfo")
	public BaseRespone saveInfo(@RequestBody RaceAdmin admin) {
		return adminService.update(admin);
	}
	
	@PostMapping("/updateAccount")
	public BaseRespone saveAccount(@RequestBody RaceAccount account) {
		return accountService.updateAccount(account);
	}

}
